import { useAppStore } from '@/store'

/**
 * JBolt websocket command配置和handler处理
 * JBolt 内置处理 请勿修改
 * 想扩展其他自定义指令 请移步到jbolt-websocket-common-extend.js
 */
const commands = {
    /**
     * 接收服务器端处理完msgcenter_check_unread指令结果 并执行响应
     * @param res  {type:3,from:xxx,to:xxx,command:xxx,data:xxx}
     */
    msgcenter_check_unread: function (res: any) {
        if (res.data) {
            useAppStore().setMessageTipShown(true)
        } else {
            useAppStore().setMessageTipShown(false)
        }
    },
    /**
     * 接收服务器处理完的check_last_pwd_update_time指令结果 true为提醒 false为不提醒
     * @param res
     */
    check_last_pwd_update_time: function (res: any) {
        if (res.data.need) {
            window.$notification?.warning({
                title: '提醒',
                content:
                    '您的账号密码已经使用【' +
                    res.data.days +
                    '】天了，系统设置密码修改周期为【' +
                    res.data.config +
                    '】天，请及时修改密码。',
                duration: 3000
            })
        }
    },
    new_notice: function (res: any) {
        useAppStore().setMessageTipShown(true)
        window.$notification?.success({
            title: '提醒',
            content: res.data,
            duration: 3000
        })
    },
    new_todo: function (res: any) {
        useAppStore().setMessageTipShown(true)
        window.$notification?.success({
            title: '新的待办',
            content: res.data,
            duration: 3000
        })
    },
    user_forced_offline: function (res: any) {
        window.$notification?.warning({
            title: '提醒',
            content: res.data,
            duration: 3000
        })
    },
    user_terminal_offline: function (res: any) {
        window.$notification?.warning({
            title: '提醒',
            content: res.data,
            duration: 3000
        })
    },
    /**
     * ping指令处理
     * @param res  {type:3,from:xxx,to:xxx,command:xxx,data:xxx}
     */
    ping: function (res: any) {
        console.debug(res)
    },
    /**
     * 接收pong指令处理
     * @param res  {type:3,from:xxx,to:xxx,command:xxx,data:xxx}
     */
    pong: function (res: any) {
        // console.debug(res)
    },
    /**
     * 接收server_time指令处理
     * @param res  {type:3,from:xxx,to:xxx,command:xxx,data:xxx}
     */
    server_time: function (res: any) {
        console.debug(res)
    }
}

export default commands
